package com.jrapider.utils;

import lombok.extern.log4j.Log4j2;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
@Log4j2
public class SpringBeanUtil implements ApplicationContextAware {

    private static ApplicationContext ctx = null;


    public void setApplicationContext(ApplicationContext ctx) throws BeansException {
        SpringBeanUtil.ctx = ctx;
    }

    public static ApplicationContext getApplicationContext() {
        return ctx;
    }

    public static <T> T getBean(String bean) {
        return (T) ctx.getBean(bean);
    }

    public static <T> T getBean(Class classType) {
        return (T) ctx.getBean(classType);
    }
}
